#include "KeyManager.h"

KeyManager* KeyManager::m_Self = NULL;

KeyManager::KeyManager()
{
	for (int i=0; i < KEY_COUNT; ++i) {
		m_Keys[i] = false;
	}
}

KeyManager::~KeyManager()
{
}

KeyManager* KeyManager::get()
{
	if (m_Self == NULL)
		m_Self = new KeyManager;
	return m_Self;
}

void KeyManager::keyPressed(SDLKey key)
{
	switch(key)
	{
	case SDLK_w: m_Keys[KEY_W] = true; break;
	case SDLK_s: m_Keys[KEY_S] = true; break;
	case SDLK_a: m_Keys[KEY_A] = true; break;
	case SDLK_d: m_Keys[KEY_D] = true; break;

	case SDLK_UP: m_Keys[KEY_UP] = true; break;
	case SDLK_DOWN: m_Keys[KEY_DOWN] = true; break;
	case SDLK_LEFT: m_Keys[KEY_LEFT] = true; break;
	case SDLK_RIGHT: m_Keys[KEY_RIGHT] = true; break;

	case SDLK_p: m_Keys[KEY_P] = true; break;
	case SDLK_q: m_Keys[KEY_Q] = true; break;
	}
}

void KeyManager::keyReleased(SDLKey key)
{
	switch(key)
	{
	case SDLK_w: m_Keys[KEY_W] = false; break;
	case SDLK_s: m_Keys[KEY_S] = false; break;
	case SDLK_a: m_Keys[KEY_A] = false; break;
	case SDLK_d: m_Keys[KEY_D] = false; break;

	case SDLK_UP: m_Keys[KEY_UP] = false; break;
	case SDLK_DOWN: m_Keys[KEY_DOWN] = false; break;
	case SDLK_LEFT: m_Keys[KEY_LEFT] = false; break;
	case SDLK_RIGHT: m_Keys[KEY_RIGHT] = false; break;

	case SDLK_p: m_Keys[KEY_P] = false; break;
	case SDLK_q: m_Keys[KEY_Q] = false; break;
	}
}

bool KeyManager::isKeyDown(KeyType key)
{
	return m_Keys[key];
}